/******************************************************************************
COPYRIGHT 2012   : ATECH
Project          : 
Source File Name : lin1Nwn.h
Group            : SoftWare Team
Author           : 
Date First Issued: 12/18/2012                                                  
******************************************************************************/

#ifndef lin1Nwn_h 
#define lin1Nwn_h



/* #include */
#include "Slave_lin1_syst.h"
#include "Slave_lin1_htype.h"
#include "system.h"

/* #define */

/* The slave node shall automatically enter bus sleep mode earliest 4 s and 
   latest 10 s of bus inactivity. */
#define LIN1_NWM_SLAVE_NODE_AUTO_SLEEP_TIME   400 /* 400@10ms=4000ms */
#define LIN1_NWM_SLAVE_NODE_QUICK_SLEEP_TIME  1 

/* If the master node does not transmit a break field (i.e. starts to transmit a frame) or if
   the node issuing the wake up signal does not receive a wake up signal (from another
   node) within 150 ms to 250 ms from the wake up signal, the node issuing the wake up
   signal shall transmit a new wake up signal */
#define LIN1_NWM_AFTER_WAKEUP_WAIT_BREAK_TIME  25 /* 25@10ms=250ms */

/* After three (failing) requests the node shall wait minimum 1.5 seconds before issuing
   a fourth wake up signal.*/    
#define LIN1_NWM_RETRY_WAKEUP_TIMES             3 /* 3 times */

    
/* typedef */
typedef enum
{
    LIN1_nenNWM_PowerOn = 0, 
    LIN1_nenNWM_WakeUp1,
    LIN1_nenNWM_WakeUp2,
    LIN1_nenNWM_Sleep,
    
}LIN1_tenNwmState;

typedef struct
{ 
	UINT16 u16DelayTime;
    UINT16 u16BusInActivityTime;
    UINT16 u16BusInActivityQuickTime;
    UINT16 u16WakeUpIntervalTime;
    UINT8  u8WakeUpTimes;
    UINT8  u8Debug1;
    UINT8  u8Debug2;
                  
}LIN1_tstNwmPara;

/* Variables */
extern LIN1_tenNwmState LIN1_enNwmState;

/* Function prototypes */
void lin1_nwm_init(void);
void lin1_nwm_vStateMachine1(void);
void lin1_hook_vBusActivity(void);
void lin1_nwm_vQuickSleep(void);
BOOL Comm_lin1_boGetSleepPermit(void);

#endif
